package com.zjw.xm.xmuser.controller;

import com.yc.common.bean.Result;
import com.zjw.xm.entity.CrUser;


import com.zjw.xm.xmuser.mapper.CrUserMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zjw1
 * @since 2022-08-03
 */
@RestController
@RequestMapping("/xm/crUser")
public class CrUserController {

    @Resource
    CrUserMapper crUserMapper;

    //查询当前用户的购物车商品
    @GetMapping("getCarts")
    public Result getCart(@SessionAttribute Map<String,Object> loginedUser){
        int id = Integer.valueOf(loginedUser.get("id")+"");
        final CrUser crUser = crUserMapper.selectWithId(id);
        return Result.success("购物车查询成功",crUser.getCrBooks());
    }
    //查询用户订单
    @GetMapping("getOrder")
    public Result getOrder(@SessionAttribute Map<String,Object> loginedUser){
        int id = Integer.valueOf(loginedUser.get("id")+"");
        final CrUser crUser = crUserMapper.selectOrderWithId(id);
        return Result.success("订单查询成功",crUser.getCrBooks());
    }
    //移除购物车
    @GetMapping("deCart")
    public Result deCart(@SessionAttribute Map<String,Object> loginedUser,int bid){
        int uid = Integer.valueOf(loginedUser.get("id")+"");
        crUserMapper.deleteCartByid(uid,bid);
        return Result.success("购物车删除成功",null);
    }
}

